package com.huluobo.a2201mvvm_imdemo.demo;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.ToastUtils;
import com.huluobo.a2201mvvm_imdemo.R;
import com.huluobo.a2201mvvm_imdemo.databinding.ActivityQrcodeBinding;
import com.huluobo.a2201mvvm_imdemo.mvvm.BaseActivity;
import com.uuzuche.lib_zxing.activity.CaptureActivity;
import com.uuzuche.lib_zxing.activity.CodeUtils;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;

public class QRCodeActivity extends BaseActivity<ActivityQrcodeBinding> {

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        //二维码初始化
        ZXingLibrary.initDisplayOpinion(this);

        requestPermissions(new String[]{"android.permission.CAMERA"}, 102);

        String str = "dd1";

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.weixin);

        Bitmap image = CodeUtils.createImage(str, 200, 200, null);
        dataBinding.imageview.setImageBitmap(image);

        dataBinding.scan.setOnClickListener(v -> {
            Intent intent = new Intent(this, CaptureActivity.class);
            startActivityForResult(intent, 101);
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 101 && resultCode == RESULT_OK) {
            String result = data.getExtras().get(CodeUtils.RESULT_STRING).toString();
            ToastUtils.showLong("二维码扫描结果:" + result);
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_qrcode;
    }
}